import { createApp } from 'vue';
import choiceOrg from "./alertModel";

const showAlertModel = (data, P_IsConfirm) => {
    // 销毁已存在的实例
    if (window.alertModel) {
        window.alertModel.unmount();
        document.body.removeChild(window.alertModel._container);
    }

    // 创建应用实例
    const instance = createApp(choiceOrg);
    
    // 存储实例和容器元素
    const container = document.createElement('div');
    document.body.appendChild(container);
    
    // 挂载应用并保存引用
    const mountedInstance = instance.mount(container);
    window.alertModel = {
        instance: mountedInstance,
        unmount: () => instance.unmount(),
        _container: container
    };

    // 调用组件方法并返回Promise
    return mountedInstance.showModal(data, P_IsConfirm);
}

export default showAlertModel;